<template>
    <div class='dialog'>
        <div class='newAdd dialog-con addChennelInfomation'>
            <split-vertical title="新增渠道信息"></split-vertical>
            <div class="form">
              <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="110px" class="demo-ruleForm" :label-position="labelPosition">
                  <el-form-item label="渠道名称" prop="channelName">
                    <el-input v-model="ruleForm.channelName"></el-input>
                  </el-form-item>
                  <el-form-item label="渠道地址" prop="channelAddress">
                    <el-input v-model="ruleForm.channelAddress"></el-input>
                  </el-form-item>
                  <el-form-item label="渠道联系人" prop="channelContact">
                    <el-input v-model="ruleForm.channelContact"></el-input>
                  </el-form-item>
                  <el-form-item label="联系人电话" prop="channelMobile">
                    <el-input v-model="ruleForm.channelMobile"></el-input>
                  </el-form-item>
                  <el-form-item class="btn" >
                    <el-button @click="submitForm('ruleForm')" type="primary" style="margin-left:-100px !important" :disabled="isChannelBtn" size="medium">创建</el-button>
                    <el-button @click="cancel"  size="medium">取消</el-button>
                  </el-form-item>
              </el-form>
            </div>
        </div>
    </div>
</template>
<script>
import SplitVertical from "components/common/SplitVertical"
import {localStorage} from 'js/localStorage'
export default {
  inject: ["reload"],
  components:{
    SplitVertical
  },
  data() {
    return {
      //创建按钮是否disabled
      isChannelBtn:false,
      labelPosition:'left',
      ruleForm: {
        channelName: "",
        channelAddress: "",
        channelContact: "",
        channelMobile: "",
      },
      rules: {
        channelName: [
          { required: true, message: '请输入渠道名称', trigger: 'blur' },
          { min: 3, max: 25, message: '长度在 3 到 25 个字符', trigger: 'blur' }
        ],
        channelAddress: [
          { required: true, message: '请输入渠道地址', trigger: 'change' }
        ],
        channelContact: [
          { required: true, message: '请输入渠道联系人', trigger: 'change' },
          { min: 2, max: 5, message: '长度在 2到 5 个字符', trigger: 'blur' }
        ],
        channelMobile: [
          { required: true, message: '请输入联系人电话', trigger: 'change' },
          {min: 11, max:11,message: '请输入正确的手机号', trigger: 'blur'}
        ]
      }
    };
  },
  created(){
    this.userId = localStorage.get("userID")
  },
  methods: {
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.confirm()
          } else {
            return false;
          }
        });
      },
    confirm() {
        let parmas = this.ruleForm
        parmas['userId']=this.userId
        this.isChannelBtn=true
        let success = data => {
          if (data.code == "OK") {
            this.$message.success("添加信息成功");
            this.isChannelBtn=false
            this.reload();
            this.$emit("closeDialog");
          } else {
            this.isChannelBtn=false
            this.$message.error(data.msg);
          }
        };
       this.api.channelAdd(parmas, success)
    },
    cancel() {
      this.$emit("closeDialog");
    }
  }
};
</script>
<style scoped>
  .addChennelInfomation .el-input{
    width:300px;
  }
  .addChennelInfomation .el-form-item__content{
    margin-left:0 !important
  }
</style>
<style lang="scss" scoped>
.addChennelInfomation {
    width: 450px;
    height: 400px;
  .companynews {
      h2 {
        height: 80px;
        line-height: 80px;
        text-indent: 20px;
        font-size: 20px;
      }
  }
  .btn{
     width:100%;
     text-align: center;
     padding-top: 30px;
     .el-button{
       margin:0 20px;
     }
    //  position:relative;
    //  top:50%;
    //  left:0;
    //  margin:auto;

    }
  .form{
    margin-left:20px;
  }
 
}
</style>

